package com.angel.config;

import com.angel.interceptor.ErrorPageInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.io.File;


@Configuration
public class ResourcesConfigAdapter extends WebMvcConfigurerAdapter {
    @Autowired
    MyConfig myConfig;

    @Autowired
    ErrorPageInterceptor errorPageInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/"+myConfig.getVitrPath()+"/**").addResourceLocations("file:"+myConfig.getFileuploadpath()+File.separator);
        super.addResourceHandlers(registry);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(errorPageInterceptor);
        super.addInterceptors(registry);
    }

}
